#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

#AC_PREREQ(2.57)
AC_INIT(mac, 3.99-u4-b4)
AC_CONFIG_SRCDIR([src/Shared/GlobalFunctions.cpp])
AC_PREFIX_DEFAULT("/usr")

AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(src/Shared/config.h)
AM_MAINTAINER_MODE

# Checks for programs.
CXXFLAGS="$CXXFLAGS -s -O3 -Wall -pedantic -Wno-long-long -DBUILD_CROSS_PLATFORM"
AC_PROG_CXX
AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET

CONFIGURE_STYLE=gnu

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h memory.h stdlib.h string.h sys/ioctl.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_C_INLINE

# Checks for library functions.
AC_FUNC_MEMCMP
AC_FUNC_STAT
#AC_CHECK_FUNCS([ftruncate memmove memset strrchr strstr])

# Checks for whether the architecture is in big endian or not.
# will define WORDS_BIGENDIAN if the arch is in big endian.
AC_C_BIGENDIAN

AC_CHECK_FUNCS(wcscasecmp)

# AC_SEARCH_LIBS (nanosleep, [rt,posix4])
# copied from videolan
AC_CHECK_FUNC(nanosleep,,[
  AC_CHECK_LIB(rt,nanosleep,LIBS="${LIBS} -lrt",[
    AC_CHECK_LIB(posix4,nanosleep,LIBS="${LIBS} -lposix4")
  ])
])

AC_MSG_CHECKING(for backward compatibility)
AC_ARG_ENABLE(backward,
  [  --enable-backward=no,yes     with backward compatibility or not],
  backward="$enableval", backward="no")
if test "$backward" = "yes"; then
  AC_DEFINE(BACKWARDS_COMPATIBILITY,,[with backward compatibility])
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

NASM= 

arch_type=other
case "$host" in
    i386-*-* | i486-*-* | i586-*-* | i686-*-* | i86pc-*-*)
        arch_type=ix86
	AC_PATH_PROG(NASM, nasm, "not found")
	;;
    powerpc-*-* )
	arch_type=powerpc
	;;
    *-*-solaris* )
    	arch_type=sparc
    	;;
esac

AM_CONDITIONAL(ARCH_X86, [test "x$arch_type" = "xix86"])
AM_CONDITIONAL(ARCH_PPC, [test "x$arch_type" = "xpowerpc"])

AC_CONFIG_FILES([Makefile src/Makefile 
			  src/Console/Makefile 
			  src/Shared/Makefile 
			  src/MACLib/Makefile 
			  src/MACLib/Assembly/Makefile
			  src/MACLib/Old/Makefile
			  src/Examples/Makefile
			  src/Examples/Analyze/Makefile
			  src/Examples/Analyze/Sample1/Makefile
			  ])
AC_OUTPUT

AC_MSG_RESULT([
Build options:
  $PACKAGE                 $VERSION
  enable-backward          $backward
])

echo -e "\nChecking status: \n";



if test "$NASM" = ""; then
	echo -e "\t1: No NASM found, you need NASM to compile the asm source in *x86* arch.\n"
else
	echo -e "\t1: NASM: $NASM\n"
fi
